﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pansoft.HIME.Base.Entities;
using Pansoft.HIME.Base.Enums;
using Pansoft.HIME.ORM;

namespace Pansoft.HIME.UnitTest.ORM
{
    [TestClass]
    public class TransactionMarketTest
    {
        const string ConntectionString = @"Data Source=(LocalDB)\v11.0; AttachDbFilename=E:\2011\hime\Pansoft.HIME.Site\App_Data\hime_transaction.mdf;Integrated Security=True";
        private TransactionMarket _Market;
        [TestInitialize]
        public void Initialize()
        {
            _Market = new TransactionMarket(ConntectionString);
        }

        [TestMethod]
        public void TestTransactionMarketConstruction()
        {
            Assert.IsNotNull(_Market.Transaction_Finished, "DbStore创建失败");
        }

        [TestMethod]
        public void TestAddDeleteTransaction()
        {
            var original = Convert.ToInt16(_Market.Transaction_Running.QueryValue("Transaction_Running",new List<string>(){"Count(*) as rscount"}));
            
            var tran = new Transaction
                {
                    FlowNo = 0,
                    TicketNumber = "A0001",
                    NumberGenerationType = NumberGenerationType.TouchScreen,
                };
            _Market.Transaction_Running.Add("Transaction_Running", tran);
            var expect = original + 1;
            var actual = Convert.ToInt16(_Market.Transaction_Running.QueryValue("Transaction_Running", new List<string>() { "Count(*) as rscount" }));
            Assert.IsTrue(expect == actual,"增加失败");

            _Market.Transaction_Running.Remove("Transaction_Running", tran);
            expect = original;
            actual = Convert.ToInt16(_Market.Transaction_Running.QueryValue("Transaction_Running", new List<string>() { "Count(*) as rscount" }));
            Assert.IsTrue(expect == actual, "删除失败");
        }
    }
}
